import { NextRequest, NextResponse } from 'next/server';
import { getDeviceParameterDb } from '@/lib/device-parameter-database';

// GET /api/device-types?specialty=配管专业
export async function GET(request: NextRequest) {
  try {
    const { searchParams } = new URL(request.url);
    const specialty = searchParams.get('specialty');
    
    const db = getDeviceParameterDb();
    
    let mappings;
    if (specialty) {
      mappings = db.getDeviceTypeMappingsBySpecialty(specialty);
    } else {
      mappings = db.getAllDeviceTypeMappings();
    }
    
    return NextResponse.json({
      success: true,
      data: mappings
    });
    
  } catch (error) {
    console.error('获取设备类型映射失败:', error);
    return NextResponse.json({
      success: false,
      error: error instanceof Error ? error.message : '获取设备类型映射失败'
    }, { status: 500 });
  }
}

